import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
    state: {
        userInfo: {},
        hasLogin: false,
		imgUrl: '',
		time: '00:00:00',
		distance:'0.00',
		semesterInfo:[],
		preLoadState:false,
		stopState: '',
		currentSemester: '',
		isBack: false,
		currentWeek: '',
		point : {},
		runningTimes : '',
		checkRunning : '',
		rweek:''
    },
    mutations: {
        saveUser(state,userInfo) {//改变登录状态
            state.hasLogin = true
			state.userInfo = userInfo
            uni.setStorage({//将用户信息保存在本地
                key: 'userInfo',
				data: userInfo
            })
        },
        cleanUser(state) {//退出登录
            state.hasLogin = false
            state.userInfo = {}
			state.semesterInfo = []
			state.imgUrl = ''
            uni.removeStorage({
                key: 'userInfo'
            })
        },
		/* 缓存图片地址 */
		changeImg(state,imgUrl) {
			state.userInfo.imgUrl = imgUrl;
			uni.setStorage({
				key: 'imgUrl',
				data: imgUrl
			})
		},
		saveTime(state,time){
			state.time = time;
			uni.setStorage({
				key:'time',
				data: time
			})
		},
		saveDistance(state,distance){
			state.distance = distance;
			uni.setStorage({
				key: 'distance',
				data: distance
			});
		},
		cleanStatistic(state){
			state.time = '00:00:00';
			state.distance = '0.00';
		},
		saveSemesterInfo(state,semesterInfo){
			state.semesterInfo = semesterInfo;
			uni.setStorage({
				key:'semesterInfo',
				data:semesterInfo
			});
		},
		changePreloadState(state,stateInfo){
			state.preLoadState = stateInfo;
		},
		saveStopState(state,stopState){
			state.stopState = stopState;
		},
		saveCurrentSemester(state,currentSemester){
			state.currentSemester = currentSemester;
			uni.setStorage({
				key: "currentSemester",
				data: currentSemester
			})
		},
		saveCurrentWeek(state,currentWeek){
			state.currentWeek = currentWeek;
			uni.setStorage({
				key: "currentWeek",
				data: currentWeek
			})
		},
		saveBackState(state,isBack){
			state.isBack = isBack;
		},
		saveStartPoint(state,startPoint){
			state.point = startPoint;
		},
		saveRunningTimes(state,runningTimes){
			state.runningTimes = runningTimes;
		},
		saveCheckRunning(state,checkRunning){
			state.checkRunning = checkRunning;
		},
		saveRweek(state,rweek){
			state.rweek = rweek;
		}
    }
})
export default store